home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_kdelibs.idb / usr / freeware / kde / include / knotebook.h.z / knotebook.h
Encoding:
C/C++ Source or Header  |  1999-01-26  |  11.3 KB  |  400 lines

  1. /*  This file is part of the KDE Libraries
  2.     Copyright (C) 1998 Thomas Tanghus (tanghus@earthling.net)
  3.  
  4.     This program is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 of the License, or (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.     General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Library General Public License
  15.     along with this library; see the file COPYING.LIB.  If not, write to
  16.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17.     Boston, MA 02111-1307, USA.
  18. */  
  19.  
  20. #ifndef __KNOTEBOOK_H
  21. #define __KNOTEBOOK_H
  22.  
  23. #ifndef KDE_KDIRECTIONBUTTON
  24. #define KDE_KDIRECTIONBUTTON
  25. #endif
  26. #ifndef KDE_KWIZARD
  27. #define KDE_KWIZARD
  28. #endif
  29. #ifndef KDE_KTABBAR
  30. #define KDE_KTABBAR
  31. #endif
  32.  
  33. #include <ktabbar.h>
  34. #include <kwizard.h>
  35.  
  36. struct KNoteBookProtected;
  37.  
  38. /**
  39. * KNoteBook is a tabbed dialog where each tab can have multiple pages.
  40. * The widget has the advantages of both KTabCtl and QTabDialog plus some more.
  41. *
  42. * Features:
  43. *
  44. * - Multiple pages per tab with previous/next button and optional arrow buttons in the title..
  45. *
  46. * - An optional popup menu which takes you to a specific page in a specific section (tab).
  47. *
  48. * - Easy additions of Ok, Cancel, Default and Help buttons.
  49. *
  50. * - Automatic resizing/repainting/repositioning of buttons. Not like QTabDialog where
  51. * there is always an Ok button.
  52. *
  53. * - Scrollable tab bar.
  54. *
  55. * - Can be used as both modal/non-modal dialog and a child widget.
  56. *
  57. * @short KNoteBook
  58. * @author Thomas Tanghus <tanghus@earthling.net>
  59. * @version 0.2
  60. */
  61. class KNoteBook : public QWidget
  62. {
  63.         Q_OBJECT
  64. public:
  65. /**
  66. * Constructs a KNoteBook.
  67. *
  68. * A modal notebook can be created like this:
  69. * <pre>
  70. * KNoteBook *nb = new KNoteBook(this, "notebook", true);
  71. * connect(nb, SIGNAL(okclicked()), SLOT(nb->hide()));
  72. * connect(nb, SIGNAL(okclicked()), SLOT(readNewInput()));
  73. * </pre>
  74. *
  75. * A very simple program where the main window is a KNoteBook with one tab
  76. * and one page inserted could look like this:
  77. * <pre>
  78. * int main(int argc, char **argv)
  79. * {
  80. *   KApplication a(argc,argv,"knotebooktest");  // create an application object
  81. *   KNoteBook *nb = new KNoteBook(); // create the notebook
  82. *   nb->setCancelButton();           // add a Cancel button and connect it to the quit() slot
  83. *   QObject::connect( nb, SIGNAL(cancelclicked()), &a, SLOT(quit()) );
  84. *   QTab *tab = new QTab;            // create a QTab to hold the tab data
  85. *   tab->label = "A tab";
  86. *   tab->enabled = true;
  87. *   nb->addTab( tab );
  88. *   QLabel *l = new QLabel(nb);
  89. *   l->setAlignment(AlignCenter);
  90. *   l->setText("This is a QLabel as a page");
  91. *   l->setMinimumSize(400, 300);
  92. *   KWizardPage *p = new KWizardPage;
  93. *   p->w = l;
  94. *   p->title.setNum("A page title");
  95. *   p->enabled = true;
  96. *   nb->addPage( p );
  97. *   a.setMainWidget(nb);
  98. *   nb->adjustSize();
  99. *   nb->show();
  100. *   return a.exec();
  101. * }
  102. </pre>
  103. * @see QDialog::QDialog
  104. *
  105. * @param parent The parent of the notebook.
  106. *
  107. * @param name The internal name.
  108. *
  109. * @param modal If modal is true the notebook wil become a modal dialog.
  110. *
  111. * @param f Window flags.
  112. */
  113.         KNoteBook(QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags f = 0);
  114. /**
  115. * Destructor
  116. */
  117.         KNoteBook::~KNoteBook();
  118. /**
  119. * Adds a new tab to the notebook and creates a new @ref KWizard to hold the pages.
  120. * The tabs are numbered from 0 to n where 0 is the tab first added and n is the
  121. * tab last added. if you add 4 tabs the last tab will be number 3. 
  122. * Subsequent calls to @ref addPage will add pages to this tab  until a new call to addTab().
  123. *
  124. * @param tab The QTab containing the tab data.
  125. *
  126. * @param p The optional KWizardPage containing the page data.If 'p' is not 0 it
  127. * will be added as a new page.
  128. * This is equivalent to @ref addPage (p);
  129. * @return Returns the id of the new tab.
  130. */
  131.         int addTab(QTab *tab, KWizardPage *p = 0L);
  132. /**
  133. * Adds a new page to the last added tab.
  134. * The pages are numbered from 0 to n where 1 is the page first added and n is the
  135. * page last added. Subsequent calls to @ref addPage will add pages to the last added
  136. * tab until a new call to addTab().
  137. *
  138. * @param p The KWizardPage containing the page data..
  139. *
  140. * @return Returns the id of the new page. The id is relative to the KWizard, NOT
  141. * the KNoteBook.
  142. */
  143.         int addPage(KWizardPage *p);
  144. /**
  145. * Turn to another tab. This method calls @ref showSection to show the corresponding KWizard.
  146. *
  147. * @param tab The tab to turn to
  148. */
  149.         void gotoTab(int tab);
  150.  
  151.         QSize sizeHint() { return minimumSize(); };
  152.         void adjustSize() { resize(sizeHint()); };
  153.  
  154. /**
  155. * Adds a Cancel button to the bottom of the dialog. The text will be a translated
  156. * version of the string '&Cancel' thereby giving it the shortcut key 'c'.
  157. * If any buttons are added a space will be created at the bottom of the dialog
  158. * to fit the buttons. When clicked the button will emit the @ref cancelclicked signal.
  159. * @see KLocale#translate
  160. */
  161.         void setCancelButton();
  162. /**
  163. * Adds a Cancel button to the bottom of the dialog.
  164. * @param text A user supplied text to write to the button.
  165. */
  166.         void setCancelButton(const char *text);
  167. /**
  168. * Adds a Default button to the bottom of the dialog. The text will be a translated
  169. * version of the string '&Default' thereby giving it the shortcut key 'd'.
  170. * If any buttons are added a space will be created at the bottom of the dialog
  171. * to fit the buttons. When clicked the button will emit the @ref defaultclicked signal.
  172. * @see KLocal::translate
  173. */
  174.         void setDefaultButton();
  175. /**
  176. * Adds a Default button to the bottom of the dialog.
  177. * @param text A user supplied text to write to the button.
  178. */
  179.         void setDefaultButton(const char *text);
  180. /**
  181. * Adds a Help button to the bottom right of the dialog. The text will be a translated
  182. * version of the string '&Help' thereby giving it the shortcut key 'h'.
  183. * If any buttons are added a space will be created at the bottom of the dialog
  184. * to fit the buttons. When clicked the button will emit the @ref helpclicked signal.
  185. */
  186.         void setHelpButton();
  187. /**
  188. * Adds a Help button to the bottom of the dialog. This button will generate the
  189. * signal @ref helpclicked where the int is the page to which the help was requested.
  190. * @param text A user supplied text to write to the button.
  191. */
  192.         void setHelpButton(const char *);
  193. /**
  194. * Adds an Ok button to the bottom right of the dialog. The text will be a translated
  195. * version of the string '&Ok' thereby giving it the shortcut key 'o'.
  196. * If any buttons are added a space will be created at the bottom of the dialog
  197. * to fit the buttons. When clicked the button will emit the @ref okclicked signal.
  198. */
  199.         void setOkButton();
  200. /**
  201. * Adds an Ok button to the bottom of the dialog. This button will generate the
  202. * signal @ref okclicked where the int is the page to which the help was requested.
  203. * @param text A user supplied text to write to the button.
  204. */
  205.         void setOkButton(const char *);
  206. /**
  207. * Get Ok button.
  208. * @return Returns the Ok buttonwidget or 0L if no button is added.
  209. */
  210.         QButton *getOkButton();
  211. /**
  212. * Get Cancel button.
  213. * @return Returns the Cancel buttonwidget or 0L if no button is added.
  214. */
  215.         QButton *getCancelButton();
  216. /**
  217. * Get Default button.
  218. * @return Returns the Default buttonwidget or 0L if no button is added.
  219. */
  220.         QButton *getDefaultButton();
  221. /**
  222. * Get Help button.
  223. * @return Returns the Help buttonwidget or 0L if no button is added.
  224. */
  225.         QButton *getHelpButton();
  226. /**
  227. * Let direction buttons reflect page.
  228. * @param state If state is true the direction buttons (Previous and Next) will have the
  229. * title of the corresponding page.
  230. * @see #directionsReflectsPage
  231. */
  232.         void setDirectionsReflectsPage(bool state);
  233. /**
  234. * @return Returns whether the direction buttons reflects the title of the corresponding page.
  235. *
  236. * @see #setDirectionsReflectsPage(bool state)
  237. */
  238.         bool directionsReflectsPage();
  239. /**
  240. * En/Disable the popup menu.
  241. * @param state If state is true a menu containing the pages in the wizard
  242. * will popup when the user RMB-clicks on the page-title.
  243. */
  244.         void setEnablePopupMenu(bool state);
  245. /**
  246. * Returns whether the menu is enabled or not.
  247. * @return 'true' if the menu is enabled, otherwise 'false'.
  248. */
  249.         bool enablePopupMenu();
  250. /**
  251. * Get the popup menu.
  252. * @return Returns the handle of the popup menu.
  253. */
  254.         QPopupMenu *getMenu();
  255. /**
  256. * En/Disable the arrowbuttons.
  257. * @param state If state is true two arrows will appear to the right of the title.
  258. * @see #enableArrowButtons
  259. * @see KWizard#setEnableArrowButtons.
  260. */
  261.         void setEnableArrowButtons(bool state);
  262. /**
  263. * @return Returns whether the arrow buttons are enabled or not.
  264. * @see #setEnableArrowButtons
  265. * @see KWizard#enableArrowButtons.
  266. */
  267.         bool enableArrowButtons();
  268. /**
  269. * Returns the handle of the tab bar.
  270. */
  271.         KTabBar *getTabBar();
  272. /**
  273. * Returns the number of tabs in the notebook.
  274. */
  275.         int numTabs();
  276. /**
  277. * En/Disable a tab in the notebook. If a tab is disabled it is not selectable
  278. * from the tab bar. If the user reaches a disabled tab by traversing through
  279. * the pages the notebook will jump to the next enabled tab.
  280. */
  281.         void setTabEnabled(int tab, bool state);
  282. /**
  283. * @return Returns whether the tab is enabled or not.
  284. * @see #setTabEnabled
  285. */
  286.         bool isTabEnabled(int tab);
  287. /**
  288. * En/Disable a page in a section (tab) in the notebook
  289. * @see KWizard#setPageEnabled
  290. */
  291.         void setPageEnabled(int tab, int page, bool state);
  292. /**
  293. * @return Returns whether a page in a section (tab) is enabled or not.
  294. * @see #setTabEnabled
  295. */
  296.         bool isPageEnabled(int tab, int page);
  297.  
  298. signals:
  299. /**
  300. * This signal is emitted when the user clicks on the Ok button.
  301. */
  302.         void okclicked();
  303. /**
  304. * This signal is emitted when the user clicks on the Cancel button.
  305. */
  306.         void cancelclicked();
  307. /**
  308. * This signal is emitted when the user clicks on the Default button.
  309. */
  310.         void defaultclicked(int);
  311. /**
  312. * This signal is emitted when the user clicks on the Help button.
  313. * The int is the page which was showing when help was requested.
  314. * @see #setHelpButton
  315. */
  316.         void helpclicked(int);
  317.  
  318. protected slots:
  319. /**
  320. * Called by @ref gotoTab to show the appropriate KWizard.
  321. */
  322.         void showSection(int);
  323. /**
  324. * If the menu is enabled by @ref enablePopupMenu this method will let the menu
  325. * popup at 'pos'.
  326. * @internal
  327. */
  328.         void popupMenu(QPoint pos);
  329. /**
  330. * @internal
  331. */
  332.         void menuChoice(int);
  333. /**
  334. * @internal
  335. */
  336.         void menuChoiceRedirect(int);
  337. /**
  338. * @internal
  339. */
  340.         void directionButton(bool, bool);
  341. /**
  342. * @internal
  343. */
  344.         void okClicked();
  345. /**
  346. * @internal
  347. */
  348.         void cancelClicked();
  349. /**
  350. * @internal
  351. */
  352.         void defaultClicked();
  353. /**
  354. * @internal
  355. */
  356.         void helpClicked();
  357. /**
  358. * @internal
  359. */
  360.         void tabScroll( ArrowType );
  361.  
  362. protected:
  363. /**
  364. * @internal
  365. */
  366.         void init();
  367. /**
  368. * @internal
  369. */
  370.         void resizeEvent(QResizeEvent *);
  371. /**
  372. * @internal
  373. */
  374.         void paintEvent(QPaintEvent *);
  375. /**
  376. * @internal
  377. */
  378.         void setSizes();
  379. /**
  380. * @internal
  381. */
  382.         QSize childSize();
  383.  
  384. /**
  385. * @internal
  386. */
  387.         KNoteBookProtected *pnote;
  388. /**
  389. * @internal
  390. */
  391.         QList<KWizard> *sections;
  392. };
  393.  
  394. #endif __KNOTEBOOK_H
  395.  
  396.  
  397.  
  398.